package com.qingdai.addresscenter.controller;


import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.query.MPJQueryWrapper;
import com.qingdai.business.emuns.Places;
import com.qingdai.business.entities.CommonResult;
import com.qingdai.business.service.PlacesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/places")
@Tag(name = "省市区")
public class PlacesController {
    @Resource
    private PlacesService placesService;

    @GetMapping("/level")
    @Operation(summary = "获取某级别省市区", description = "获取某级别省市区")
    @Parameters({
            @Parameter(name = "level", description = "省/市/区", required = true),
    })
    public CommonResult<List<Places>> getPlaceByLevel(Integer level) {
        MPJQueryWrapper<Places> mpjQueryWrapper = new MPJQueryWrapper<>();
        mpjQueryWrapper.select("*").eq("ctype", level);
        List<Places> list = placesService.list(mpjQueryWrapper);
        return new CommonResult<>(200, "获取某级别省市区", list);
    }

    @GetMapping("/below")
    @Operation(summary = "获取某级别省市区下级", description = "获取某级别省市区下级")
    @Parameters({
            @Parameter(name = "parentId", description = "父级id", required = true),
    })
    public CommonResult<List<Places>> getPlaceByParentId(Integer parentId) {
        MPJQueryWrapper<Places> mpjQueryWrapper = new MPJQueryWrapper<>();
        mpjQueryWrapper.select("*").eq("parent_id", parentId);
        List<Places> list = placesService.list(mpjQueryWrapper);
        return new CommonResult<>(200, "获取某级别省市区下级", list);
    }



}
